module Api
  class InformationClerkController < ApplicationController
    include Apiable
    include MerchantHelper

    def new_session
      user = get_information_clerk_by(mobile: params[:mobile])
      if user.blank?
        error! "用户不存在"
      else
        data!
      end
    end

    def delete_session
      data!
    end

    def session_user
      user = api_current_user
      result = {
        name: user.name,
        mobile: user.mobile,
        today: get_user_count_by(user.id, beginning_of_today),
        total: Merchant.where(information_clerk_id: user.id).count,
      }
      data! result
    end
  end
end